home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / doslynx / src / urltodos.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  3.1 KB  |  115 lines

  1. //    Copyright (c) 1994, University of Kansas, All Rights Reserved
  2. //
  3. //    Class:        none
  4. //    Include File:    urltodos.h
  5. //    Purpose:    convert a url path to a dos path
  6. //    Remarks/Portability/Dependencies/Restrictions:
  7. //    Revision History:
  8. //        01-18-94    created
  9. #include"urltodos.h"
  10. #include"trace.h"
  11. #include<string.h>
  12.  
  13. extern "C" void urltodos(char *cp_url)    {
  14. //    Purpose:    convert a url to a dos path
  15. //    Arguments:    cp_url    the url to convert
  16. //    Return Value:    void
  17. //    Remarks/Portability/Dependencies/Restrictions:
  18. //        Will overwrite the cp_url memory in order to provide the new
  19. //            path.
  20. //        Does not actually take a complete url, only the part passed
  21. //            in by a routine in htfile.c
  22. //    Revision History:
  23. //        01-18-94    created
  24.  
  25.     //    Allocate space for the new name.
  26.     //    Remember the address of the original url
  27.     char *cp_newurl = new char[strlen(cp_url) + 1];
  28.     char *cp_oldurl = cp_url;
  29.  
  30.     //    Skip the always leading '/'
  31.     cp_url++;
  32.  
  33.     //    Next comes the drive letter.
  34.     *cp_newurl = *cp_url;
  35.     cp_url++;
  36.  
  37.     //    If the last character was a drive letter, this will be
  38.     //    a '|', if not, the rest must be a file name.
  39.     if(*cp_url == '|')    {
  40.         *(cp_newurl + 1) = ':';
  41.     }
  42.     else    {
  43.         //    Just copy over another character.
  44.         *(cp_newurl + 1) = *cp_url;
  45.     }
  46.  
  47.     //    Move past the '|'
  48.     cp_url++;
  49.  
  50.     //    Copy the rest of the string over.
  51.     strcpy(cp_newurl + 2, cp_url);
  52.  
  53.     //    Loop through the string, converting all '/' to '\\'
  54.     for(cp_url = cp_newurl; *cp_url != '\0'; cp_url++)    {
  55.         if(*cp_url == '/')    {
  56.             *cp_url = '\\';
  57.         }
  58.     }
  59.  
  60.     //    Done, copy back over the new url, and release our memory.
  61. #ifndef RELEASE
  62.     trace("Converted " << cp_oldurl << " to " << cp_newurl);
  63. #endif // RELEASE
  64.     strcpy(cp_oldurl, cp_newurl);
  65.     delete[](cp_newurl);
  66. }
  67.  
  68. extern void dostourl(char *cp_dest, const char *cp_dospath)    {
  69. //    Purpose:    convert a dos path to a url
  70. //    Arguments:    cp_dest        the buffer to put the url in
  71. //            cp_dospath    the dos path to convert
  72. //    Return Value:    void
  73. //    Remarks/Portability/Dependencies/Restrictions:
  74. //        Will return a full url.  What is returned is generally
  75. //            not passable back to usltodos as the beginning
  76. //            'file://' should be stripped off before passing.
  77. //    Revision History:
  78. //        01-19-94    created
  79.  
  80.     //    Copy the leading 'file:///' into cp_dest
  81.     strcpy(cp_dest, "file:///");
  82.     //    Append the dos part.
  83.     strcat(cp_dest, cp_dospath);
  84.  
  85.     //    Go through cp_dest, changing '\\' to '/' and ':' to '|'
  86.     for(int i_traverse = 8; *(cp_dest + i_traverse) != '\0';
  87.         i_traverse++)    {
  88.         switch(*(cp_dest + i_traverse))    {
  89.         case '\\':
  90.             *(cp_dest + i_traverse) = '/';
  91.             break;
  92.         case ':':
  93.             *(cp_dest + i_traverse) = '|';
  94.             break;
  95.         }
  96.     }
  97. #ifndef RELEASE
  98.     trace("Converted " << cp_dospath << " to " << cp_dest);
  99. #endif // RELEASE
  100. }
  101.  
  102.  
  103. extern int URLisLocal(const char *cp_URL)    {
  104. //    Purpose:    Determine if a URL is local.
  105. //    Arguments:    cp_URL    the url in question
  106. //    Return Value:    int    0    is not local
  107. //                1    is local
  108. //    Remarks/Portability/Dependencies/Restrictions:
  109. //        Assuming a URL is local on dos only when "file:///" is the
  110. //            prefix of the URL.
  111. //    Revision History:
  112. //        01-19-94    created
  113.  
  114.     return((strncmp(cp_URL, "file:///", 8) == 0) ? 1 : 0);
  115. }